Skip to content

Use emit_ptr_va_arg for va_arg on M68k - #165465

Open
beetrees wants to merge 1 commit into
rust-lang:mainfrom
beetrees:va-arg-m68k
Open

beetrees wants to merge 1 commit into
rust-lang:mainfrom
beetrees:va-arg-m68k

Conversation

@beetrees

@beetrees beetrees commented Nov 4, 2026

Copy link
Copy Markdown
Contributor

This avoids using the LLVM va_arg instruction. AFAICT LLVM's implementation currently miscompiles the va_arg instruction for f64 (and needlessly aligns the pointer that is guaranteed to be aligned for i32 and i64) - this PR matches GCC (checked by comparing the assembly).

Ping target maintainers: @glaubitz @ricky26 @knickish

r? @folkertdev

@rustbot rustbot added A-LLVM Area: Code generation parts specific to LLVM. Both correctness bugs and optimization-related issues. S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Nov 4, 2026
@beetrees beetrees added the O-motorola68k Target: Rust from the parallel universe where the Amiga won. label Nov 4, 2026
@rust-bors

This comment has been minimized.

@rustbot

This comment has been minimized.

@folkertdev

Copy link
Copy Markdown
Contributor

As discussed in #rustc-codegen-gcc > ABI of m68k, there are several ABIs for m68k and the current rust targets don't match GCC overall, so I'm not sure it should be the reference for the rustc implementation.

Hopefully the target maintainers can shine a light on the situation?

@glaubitz

glaubitz commented Nov 7, 2026

Copy link
Copy Markdown
Contributor

As discussed in #rustc-codegen-gcc > ABI of m68k, there are several ABIs for m68k and the current rust targets don't match GCC overall, so I'm not sure it should be the reference for the rustc implementation.

Hopefully the target maintainers can shine a light on the situation?

There is actually just one official SysV m68k ELF ABI.

Linux is off-standard and I'm working on changing that as explained on the Debian Wiki.

NetBSD/ELF is using the proper ABI, Linux isn't.

@folkertdev

Copy link
Copy Markdown
Contributor

So to be clear, you would support rust matching GCC's va_arg right now? And the implementation here matches the desired ABI as far as you can tell?

@rust-bors

This comment has been minimized.

@rustbot

rustbot commented Nov 8, 2026

Copy link
Copy Markdown
Collaborator

This PR was rebased onto a different main commit. Here's a range-diff highlighting what actually changed.

Rebasing is a normal part of keeping PRs up to date, so no action is needed—this note is just to help reviewers.

@beetrees

Copy link
Copy Markdown
Contributor Author

For the types Rust currently supports (f64, i32/u32, i64/u64 and equivalent) the implementation in this PR matches (AFAICT) how both GCC and Clang currently pass arguments (LLVM/Clang's va_arg doesn't match its own argument passing) and the SysV m68k ELF ABI mentioned above (i.e. 4 byte stack slots with no extra alignment required), so this implementation should be forwards compatible with any changes to bring the ABI closer to the SysV standard.

@rust-bors

rust-bors Bot commented Nov 12, 2026

Copy link
Copy Markdown
Contributor

☔ The latest upstream changes (presumably #165844) made this pull request unmergeable. Please resolve the merge conflicts by rebasing.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

A-LLVM Area: Code generation parts specific to LLVM. Both correctness bugs and optimization-related issues. O-motorola68k Target: Rust from the parallel universe where the Amiga won. S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants